package com.iptv.grape.event.imp;

import android.text.TextUtils;

import com.google.gson.Gson;
import com.iptv.grape.BaseActivity;
import com.iptv.grape.event.JSRequest;
import com.iptv.grape.event.msg.ApkArgsData;
import com.iptv.grape.event.proc.IWebViewMessageProc;
import com.iptv.grape.beans.LoadApkBean;
import com.iptv.grape.load_apk.LoadBack;
import com.iptv.grape.load_apk.LoadBackImp;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.video.XMediaPlayer;

// 跳转到第三方应用
public class GotoApk implements IWebViewMessageProc {

    ApkArgsData argsData;
    @Override
    public void init(JSRequest jsRequest) {
        try {
           LoadApkBean bean  = new Gson().fromJson(jsRequest.getJson(), LoadApkBean.class);
            argsData = bean.data;
            if(TextUtils.isEmpty(argsData.getAppName())){
                argsData.setAppName(bean.id);
            }
        }
        catch (Exception e){
            argsData = null;
        }
    }

    @Override
    public String procMessage(BaseActivity baseActivity, XMediaPlayer mediaPlayer) {
        if(argsData != null){
            AppLog.getCurLog().out(argsData.getAppName());
            AppLog.getCurLog().out(argsData.getPackageName());
            AppLog.getCurLog().out(argsData.getUrl());
//            com.wjtv
           LoadBackImp loadBackImp = LoadBack.ISTC().getLoadBack();
           if(null!=loadBackImp)
               loadBackImp.loadApk(argsData);
        }
        return "";
    }


}
